<template>
  <div class="prolist">
    <div class="tit">
      面部护理
      <span>季節のケア</span>
    </div>
    <ly-tab
    v-model="selectedId"
    :items="items"
    :options="options"
    @change="changeList">
    </ly-tab>
    <div class="productsort">
      <span @click="sort(1)" :class="{active:activetop}">销量</span>
      <span @click="sort(2)" :class="{active:activebottom}">价格</span>
      <span>
        <div :class="{top:true,active:sjActive}"></div>
        <div :class="{bottom:true,active:!sjActive}"></div>
      </span>
    </div>
    <ul class="list" v-infinite-scroll="loadMore"
  infinite-scroll-disabled="loading"
  infinite-scroll-distance="10">
      <li v-for="(item,index) in list" :key="index">
        <div class="top">
          <img src="../../assets/images/icon3.png" alt="">
        </div>
        <div class="bot">
          <div class="gq">
            <p></p>
          </div>
          <p class="proInfo">BIORE 碧柔 水活防晒霜
SPF50+PA++ 50g</p>
          <div class="price">
            <span>￥65</span>
            <div class="addShop"></div>
          </div>
        </div>
      </li>
    </ul>
    <div class="load">
      <mt-spinner type="double-bounce"></mt-spinner>
      <span style="float:left;">正在加载</span>
    </div>
  </div>
</template>

<script>
import { InfiniteScroll } from 'mint-ui';
export default {

  data () {
    return {
      selectedId: 0,
      items: [
        {label: '首页'},
        {label: '推荐'},
        {label: 'Android'},
        {label: '前端'},
        {label: '后端'},
        {label: 'iOS'},
        {label: '产品'},
        {label: '人工智能'},
        {label: '设计'}
      ],
      options: {
        activeColor: '#fff',
        // 可在这里指定labelKey为你数据里文字对应的字段
      },
      activetop:true,
      activebottom:false,
      sjActive:true,
      list:[1,2,3,4,5,6,6,6],
      loading:false
    }
  },

  methods: {
    changeList(item,index){
      console.log(item)
      var elAll = document.querySelectorAll('.ly-tab-item')
      for(var i=0; i <elAll.length; i++){
        elAll[i].style.background = "#FDDF00"
        elAll[i].style.color = '#000'
      }
      var el = document.querySelector('.ly-tab-item:nth-of-type('+(index+1)+')')
      el.style.background = "#003A9B"
      el.style.color = '#fff'
    },
    sort(num){
      if(num==1){
        
        if(this.activetop){
          this.sjActive = !this.sjActive
        }else{
          this.sjActive = true
        }
        this.activetop = true
        this.activebottom = false
      }else{
        
        if(this.activebottom){
          this.sjActive = !this.sjActive
        }else{
          this.sjActive = true
        }
        this.activetop = false
        this.activebottom = true
      }
    },
    loadMore() {
      this.loading = true;
      setTimeout(() => {
        let last = this.list[this.list.length - 1];
        for (let i = 1; i <= 10; i++) {
          this.list.push(last + i);
        }
        this.loading = false;
      }, 500);
    }
  },

  created () {
    
  },
  mounted(){
    document.querySelector('.ly-tab-item').style.background = "#003A9B"
    document.querySelector('.ly-tab-item').style.color = '#fff'
  }
}
</script>

<style lang='less' scoped>

.productsort{
  text-align: right;
  vertical-align: bottom;
  padding: 10px;
  border-bottom:1px solid #e7e7e7;
  span:nth-child(1){
    margin-right: 5px;
    &.active{
      color: #999;
    }
  }
  span:nth-child(2){
    margin:5px 5px;
    &.active{
      color: #999;
    }
  }
  span:nth-child(3){
    width:11px;
    height:16px;
    position: relative;
    display: inline-block;
    .top,.bottom{
      position: absolute;
      width:9px;
      height:6px;
      font-size: 14px;
      color: #333333;
    }
    
    .top{
      top:2px;
      border-width:0 6px 6px;
      border-style:solid;
      border-color:transparent transparent #ccc;/*透明 透明  灰*/
    }
    .bottom{
      bottom:-2px;
      border-width:6px 6px 0 ;
      border-style:solid;
      border-color:#ccc transparent transparent;/*灰 透明 透明 */
    }
    .bottom.active{
      border-color:#333 transparent transparent;/*灰 透明 透明 */
    }
    .top.active{
      border-color: transparent transparent #666;/*灰 透明 透明 */
    }
  }
}
.prolist{
  .list{
    width:100%;
    list-style: none;
    padding: 0;
    display: flex;
    justify-content: space-between;
    flex-wrap:wrap;
    li{
      width:47%;
      border: 1px solid #E7E7E7;
      border-radius: 10px;
      margin-bottom:10px;
      .top{
        width:100%;
        height:120px;
        min-height: 120px;
        background: #F9F9FB;
        text-align: center;
        img{
          height:80px;
          margin: 19px;
        }
      }
      .bot{
        font-size: 12px;
        color: #333333;
        padding: 16px 13px;
        .gq{
          width:14px;
          height:10px;
          border: 1px solid #F2F2F2;
          p{
            width:4px;
            height:4px;
            margin: 2.5px 4px;
            background: red;
            border-radius:2px;
          }
        }
        .proInfo{
          color: #333333;
          font-size: 12px;
          line-height: 16px;
          margin: 4px 0;
        }
        .price{
          display: flex;
          justify-content: space-between;
          margin: 6px 0px 0px 0px;
          span{
            font-size: 14px;
            color: #E4007B;
          }
          .addShop{
            width:26px;
            height:21px;
            background: url("../../assets/images/icon1.png");
            background-size:26px 21px;
          }
        }
      }
      
    }
  }
  .load{
    display: flex;
    justify-content: center;
    span{
      font-size: 14px;
      line-height: 33px;
      display: inline-block;
      margin-left: 10px;
      color:#666;
    }
  }
}
</style>
